package com.fly.studio.home.manage.domain.response;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * 公共响应
 *
 * @author Mr.Fu
 * @date 2022/9/3 下午12:09
 */
@Setter
@Getter
@ToString
public class ResponseVO<D> {
    /**
     * 是否成功：true-成功；false-失败
     */
    private Boolean success;
    /**
     * 响应码
     */
    private Integer code;
    /**
     * 响应提示
     */
    private String message;
    /**
     * 响应数据
     */
    private D data;

    public static <D> ResponseVO<D> success() {
        ResponseVO<D> responseVO = new ResponseVO<>();
        responseVO.success = true;
        responseVO.code = 200;
        responseVO.message = "SUCCESS";
        return responseVO;
    }

    public static <D> ResponseVO<D> success(D data) {
        ResponseVO<D> responseVO = new ResponseVO<>();
        responseVO.success = true;
        responseVO.code = 200;
        responseVO.message = "SUCCESS";
        responseVO.data = data;
        return responseVO;
    }

    public static <D> ResponseVO<D> fail() {
        ResponseVO<D> responseVO = new ResponseVO<>();
        responseVO.success = false;
        responseVO.code = 500;
        responseVO.message = "FAIL";
        return responseVO;
    }

    public static <D> ResponseVO<D> fail(String message) {
        ResponseVO<D> responseVO = new ResponseVO<>();
        responseVO.success = false;
        responseVO.code = 500;
        responseVO.message = message;
        return responseVO;
    }

    public static <D> ResponseVO<D> fail(Integer code, String message) {
        ResponseVO<D> responseVO = new ResponseVO<>();
        responseVO.success = false;
        responseVO.code = code;
        responseVO.message = message;
        return responseVO;
    }
}
